<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <th:block th:include="views/include :: header('添加项目')"/>
</head>
<body>
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body ">
            <form class="layui-form layui-table-form" lay-filter="log-table-form">
                <div class="layui-row">
                    <div class="layui-col-md10">
<!--                        <div class="layui-form-item">-->
<!--                            <div class="layui-inline">-->
<!--                                <label class="layui-form-label layui-form-label-sm">操作人</label>-->
<!--                                <div class="layui-input-inline">-->
<!--                                    <input type="text" name="username" autocomplete="off" class="layui-input">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="layui-inline">-->
<!--                                <label class="layui-form-label layui-form-label-sm">操作时间</label>-->
<!--                                <div class="layui-input-inline">-->
<!--                                    <input type="text" name="createTime" id="log-createTime" class="layui-input">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="layui-inline">-->
<!--                                <label class="layui-form-label layui-form-label-sm">操作描述</label>-->
<!--                                <div class="layui-input-inline">-->
<!--                                    <input type="text" name="operation" autocomplete="off" class="layui-input">-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </div>-->
                    </div>

                </div>
            </form>
            <table lay-filter="logTable" id="logTable" lay-data="{id: 'logTable'}"></table>
        </div>
    </div>
</div>
<script type="text/html" id="log-time">
    <div>
        {{# if (d.time < 500) { }}
        <span class="layui-badge  ">{{d.time}} ms</span>
        {{# } else if (d.time < 1000) { }}
        <span class="layui-badge ">{{d.time}} ms</span>
        {{# } else if (d.time < 1500) { }}
        <span class="layui-badge">{{d.time}} ms</span>
        {{# } else { }}
        <span class="layui-badge ">{{d.time}} ms</span>
        {{# } }}
    </div>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'laydate', 'form', 'table'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            form = layui.form,
            table = layui.table;

        laydate.render({
            elem: '#log-createTime',
            range: true,
            trigger: 'click'
        });
        form.render();
        initTable();


        table.on('tool(logTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                // febs.modal.confirm('删除日志', '确定删除该条系统日志？', function () {
                //     deleteLogs(data.id);
                // });
            }
        });

        table.on('sort(logTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });


        function initTable() {
            let tab_tab = table.render({
                elem: "#logTable",
                id: 'logTable',
                url: '/log/list',
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'username', title: '操作人'},
                        {field: 'operation', title: '操作描述'},
                        {field: 'time', title: '耗时', templet: "#log-time", sort: true},
                        {field: 'method', title: '操作方法'},
                        {field: 'params', title: '方法参数'},
                        {field: 'ip', title: 'IP地址'},
                        {field: 'location', title: '操作地点'},
                        {field: 'createTime', title: '创建时间', minWidth: 180, sort: true}
                        // {title: '操作', toolbar: '#log-option'}
                    ]
                ]
            });
        }

        function deleteLogs(logIds) {
            // febs.get(ctx + 'log/delete/' + logIds, null, function () {
            //     febs.alert.success('删除系统日志成功');
            //     $query.click();
            // });
        }

        function getQueryParams() {
            var createTime = $searchForm.find('input[name="createTime"]').val();
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            return {
                createTimeFrom: createTimeFrom,
                createTimeTo: createTimeTo,
                username: $searchForm.find('input[name="username"]').val().trim(),
                operation: $searchForm.find('input[name="operation"]').val().trim(),
                invalidate_ie_cache: new Date()
            };
        }
    })
</script>


</body>
</html>